<template>
  <div class="box6">
    <div class="title">
      <p>热门景区排行</p>
      <img src="../../images/dataScreen-title.png" alt="" />
    </div>
    <div class="charts" ref="charts"></div>
  </div>
</template>

<script setup lang="ts">
import { ref, onMounted } from 'vue'
import * as echarts from 'echarts'
let charts = ref()

onMounted(() => {
  let myCharts = echarts.init(charts.value)
  myCharts.setOption({
    title: {
      //主标题
      text: '景区排行',
      textStyle: {
        color: 'white',
      },
      //top:'10%',
      left: '40%',
      // //子标题
      // subtext:'各大景区排行',
      // //子标题样式
      // subtextStyle:{
      //     color:'white',
      //     fontSize:16,
      // },
    },
    xAxis: {
      type: 'category',
      axisLine: {
        show: true,
        lineStyle: {
          color: 'white',
        },
      },
      data: ['井冈山', '六里铺', '卓望塔', '东方明珠', '百鹭洲', '华南虎'],
    },
    yAxis: {
      axisLine: {
        show: true,
        lineStyle: {
          color: 'white',
        },
      },
      splitLine: {
        show: false,
      },
    },
    series: [
      {
        type: 'bar',
        data: [1, 2, 4, 5, 3, 6],
        //柱状图的标签
        label: {
          show: true,
          //标签位置
          position: 'top',
          color: 'white',
        },
        //显示背景
        showBackground: true,
        //背景颜色
        backgroundStyle: {
          color: {
            tyle: 'linear',
            x: 0,
            y: 0,
            x2: 0,
            y2: 1,
            colorStops: [
              {
                offset: 0,
                color: 'rgb(17,20,78)',
              },
              {
                offset: 1,
                color: 'rgb(1,52,129)',
              },
            ],
            global: false,
          },
        },
        //柱条样式
        itemStyle: {
          borderRadius: 10,
          //柱条颜色
          color: function (data: any) {
            let arr = ['red', 'blue', 'green', 'pink', 'orange', 'silver']
            return arr[data.dataIndex]
          },
        },
      },
      //一个容器可以放多个图标
      {
        type: 'line',
        data: [1, 2, 4, 5, 3, 6],
        color: 'white',
      },
    ],
    grid: {
      top: 30,
      right: 0,
      left: 20,
      bottom: 20,
    },
  })
})
</script>

<style scoped lang="scss">
.box6 {
  width: 100%;
  height: 100%;
  background: url(../../images/dataScreen-main-lb.png) no-repeat;
  background-size: 100% 100%;
  margin: 5px 0px;
  .title {
    margin-top: 10px;
    margin-left: 20px;
    color: white;
    font-size: 25px;
  }

  .charts {
    width: 100%;
    height: calc(100% - 30px);
  }
}
</style>
